package com.jaya.budan.base;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.baidu.mobstat.StatService;

public class BaseFragment extends Fragment {

    public boolean mHaveLoadData; // 表示是否已经请求过数据
    // 表示开始加载数据, 但不表示数据加载已经完成
    public void loadDataStart(){

    }
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        // 如果还没有加载过数据 && 用户切换到了这个fragment
        // 那就开始加载数据
        if (!mHaveLoadData && isVisibleToUser) {
            loadDataStart();
            mHaveLoadData = true;
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        StatService.onPause(getActivity());
    }

    @Override
    public void onResume() {
        super.onResume();
        StatService.onResume(getActivity());
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
